<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <!-- Title and other stuffs -->
  <title>注册</title> 
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="author" content="">
  <!-- Stylesheets -->
  <link href="style/bootstrap.css" rel="stylesheet">
  <link rel="stylesheet" href="style/font-awesome.css">
  <link href="style/style.css" rel="stylesheet">
  <link href="style/bootstrap-responsive.css" rel="stylesheet">
  
  <!-- HTML5 Support for IE -->
  <!--[if lt IE 9]>
  <script src="js/html5shim.js"></script>
  <![endif]-->

  <!-- Favicon -->
  <link rel="shortcut icon" href="img/favicon/favicon.png">
</head>


<body onload="myLoad()">

<div class="admin-form">
  <div class="container">
    <div class="row">
      <div class="col-lg-12">
        <!-- Widget starts -->
            <div class="widget wred">
              <div class="widget-head">
                <i class="icon-lock"></i> 注册 
              </div>
              <div class="widget-content">
                <div class="padd">
                  
                  <form class="form-horizontal" action="./RegisterServlet" method="post" onsubmit="return checkInput();">
                    <!-- Registration form starts -->
                    <!-- LoginName -->
                    <div class="form-group">
                      <label class="control-label col-lg-3" for="name">登录名</label>
                      <div class="col-lg-9">
                        <input type="text" class="form-control" id="txtLoginName" name="txtLoginName" placeholder="登录名">
                        <span class="label label-danger" id="spanLoginName"></span>
                        
                      </div>
                    </div>   
                    <!-- Password -->
                    <div class="form-group">
                      <label class="control-label col-lg-3" for="email">密码</label>
                      <div class="col-lg-9">
                        <input type="password" class="form-control" id="txtPassword" name="txtPassword" placeholder="密码">
                        <span class="label label-danger" id="spanPassword"></span>
                      </div>
                    </div>
                    <!-- RPassword -->
                    <div class="form-group">
                      <label class="control-label col-lg-3" for="email">确认密码</label>
                      <div class="col-lg-9">
                        <input type="password" class="form-control" id="txtRPassword" name="txtRPassword" placeholder="确认密码">
                        <span class="label label-danger" id="spanRPassword"></span>
                      </div>
                    </div>
                    <!-- Email -->
                    <div class="form-group">
                      <label class="control-label col-lg-3" for="email">Email</label>
                      <div class="col-lg-9">
                        <input type="text" class="form-control" id="txtEmail" name="txtEmail" placeholder="Email">
                        <span class="label label-danger" id="spanEmail"></span>
                      </div>
                    </div>
                    <!-- Nickname -->
                    <div class="form-group">
                      <label class="control-label col-lg-3" for="email">昵称</label>
                      <div class="col-lg-9">
                        <input type="text" class="form-control" id="txtNickname" name="txtNickname" placeholder="昵称">
                      </div>
                    </div>
                    <!-- Accept box and button s-->
                    <div class="form-group">
                    <div class="col-lg-9 col-lg-offset-3">
					<div class="checkbox">
                    <label>
                      <input type="checkbox" id="chkAccept" onclick="myAccept()"> 已阅读并接受
                    </label>
					</div>
                     <br />
                      <button type="submit" class="btn btn-danger" id="btnRegister" disabled="disabled">注册</button>
                      <button type="reset" class="btn btn-success">取消</button>
                    </div>
                    </div>
  					<br />
                  </form>

                </div>
              </div>
                <div class="widget-foot">
                  是否已注册? <a href="./LoginServlet">登录</a>
                </div>
            </div>  
      </div>
    </div>
  </div> 
</div>
	
		

<!-- JS -->
<script src="js/jquery.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript">
function checkInput(){
	var flag = true;
	var txtLoginName = document.getElementById("txtLoginName");
	var spanLoginName = document.getElementById("spanLoginName");
	var txtPassword = document.getElementById("txtPassword");//通过Id在文档中获得元素，id;某一个表单的属性，通常用来表示表单当中唯一的元素
	var spanPassword = document.getElementById("spanPassword");
	var txtRPassword = document.getElementById("txtRPassword");//通过Id在文档中获得元素，id;某一个表单的属性，通常用来表示表单当中唯一的元素
	var spanRPassword = document.getElementById("spanRPassword");
	var txtEmail = document.getElementById("txtEmail");//通过Id在文档中获得元素，id;某一个表单的属性，通常用来表示表单当中唯一的元素
	var spanEmail = document.getElementById("spanEmail");

	
	if(txtLoginName.value.length == 0){
		spanLoginName.innerHTML = "登录名不能为空。";
		flag = false;
	}
	else if(txtLoginName.value.length < 5){
		spanLoginName.innerHTML = "登录名不能少于5个字符。";
		flag = false;
	}
	else{
		spanLoginName.innerHTML="";	
	}
	
	if(txtPassword.value.length == 0){
		spanPassword.innerHTML = "密码不能为空。";	
		flag = false;	
	}
	else if(txtPassword.value.length < 5){
		spanPassword.innerHTML = "密码至少5个字符。";
		flag = false;	
	}
	else {
		spanPassword.innerHTML="";	
	}
	
	if(txtPassword.value.length == 0){
		spanRPassword.innerHTML = "";	
	}
	else if(txtRPassword.value != txtPassword.value){
		spanRPassword.innerHTML = "确认密码与密码不一致";
		flag = false;	
	}
	else {
		spanRPassword.innerHTML="";	
	}
	
	//正则表达式
	//字符串的匹配和验证。
	var patten = new RegExp(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]+$/);
	if(txtEmail.value.length == 0){
		spanEmail.innerHTML = "Email不能为空。";	
		flag = false;	
	}
	else if(!patten.test(txtEmail.value)){
		spanEmail.innerHTML = "Email格式错误。";
		flag = false;	
	}
	else {
		spanEmail.innerHTML="";	
	}

	return flag;
}

function myAccept(){
	var btnRegister = document.getElementById("btnRegister");
	var chkAccept = document.getElementById("chkAccept");
	btnRegister.disabled = !chkAccept.checked;
}

function myLoad(){
 ${alertMessage}
}
</script>
</body>
</html>